import request from './request'
import { useUserStore } from '../store/modules/user'
//获取服务商列表
export function getnetworkList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getList',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取所有服务商下拉数据
 * @param data - 请求参数
 * @param data.factoryId - 品牌商家id
 * @param data.limit - 每页显示数量
 * @param data.name - 搜索关键词
 * @param data.page - 当面页码
 */
export function getNetworkPageSelect(data: {
  factoryId: string
  limit: number
  name: string
  page: number
}) {
  return request({
    url: '/networkSelect/getNetworkPageSelect',
    method: 'post',
    data,
  })
}

// 根据服务商ID获取服务商详情
export function getnetworkDetail(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getDetail/' + id,
    method: 'get',
    headers: token,
  })
}
// 批量启用或禁用服务商
export function setDisable(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}
// 批量删除服务商
export function setDelete(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/delete',
    method: 'DELETE',
    headers: token,
    data,
  })
}
// 新增或修改服务商
export function addNetwork(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 分页获取服务商类型下拉数据
export function networkTypePageSelect(data: { limit: number; name: string; page: number }) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/networkTypePageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 获取服务商详情之工单明细列表
export function getNetworkDetailOrderList(data, networkId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailOrderList/' + networkId,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取服务商详情之服务商人员列表
export function getNetworkDetailEmpList(data, networkId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailEmpList/' + networkId,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取服务商详情之服务商人员列表的详情
 * @param {string} empRelationId 服务商人员关联ID
 * @param {string} id 服务人员ID
 * @returns {Promise<any>}
 */
export function getNetworkDetailEmpListDetail(empRelationId: string, id: string) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/getNetworkDetailEmpListDetail/${id}`,
    method: 'get',
    headers: token,
    params: { empRelationId },
  })
}

// 新增或修改服务商人员
export function empSave(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/save',
    method: 'post',
    headers: token,
    data,
  })
}
// 根据服务人员关联ID删除服务商人员
export function deleteNetworkEmp(empRelationId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/deleteNetworkEmp/' + empRelationId,
    method: 'DELETE',
    headers: token,
  })
}
//  获取服务商人员下拉数据
export function getNetworkEmpPageSelect(data, networkId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkEmpPageSelect/' + networkId,
    method: 'post',
    headers: token,
    data,
  })
}

//获取服务商字段列表
export function getnetworkSerList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/getList',
    method: 'post',
    headers: token,
    data,
  })
}

//新增或修改服务商自定义字段
export function saveNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/save',
    method: 'post',
    headers: token,
    data,
  })
}

//批量启用或禁用服务商字段
export function batchDisableNetworkField(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

//批量删除服务商字段
export function deleteNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/delete',
    method: 'delete',
    headers: token,
    data,
  })
}

// 获取服务商字段详情
export function getServiceInfo(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/network/field/getDetail/' + id,
    method: 'post',
  })
}

// 获取服务商人员字段详情
export function getNetworkEmpFieldDetail(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/network/emp/field/getDetail/' + id,
    method: 'post',
  })
}

//新增或修改服务商人员自定义字段
export function saveNetworkEmpField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/save',
    method: 'post',
    headers: token,
    data,
  })
}

//获取服务商人员字段列表
export function getNetworkEmpList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/getList',
    method: 'post',
    headers: token,
    data,
  })
}

//批量启用或禁用服务商人员字段
export function batchUpdateNetworkEmpFieldStatus(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

//批量删除服务商字段
export function delNetworkEmpField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/delete',
    method: 'delete',
    headers: token,
    data,
  })
}
//   获取修改服务商前的信息
export function getBeforeNetworkEditSelect(networkId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getBeforeNetworkEditSelect/' + networkId,
    method: 'get',
    headers: token,
  })
}
// 获取服务商字段下拉数据
export function networkFieldSelect() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/networkFieldSelect',
    method: 'get',
    headers: token,
  })
}

// 服务人员列表接口
export function getEmpList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/getList',
    method: 'POST',
    headers: token,
    data,
  })
}

//获取服务商详情之工单配件列表
export function getNetworkDetailOrderSpareList(data, id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailOrderSpareList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
//获取服务商详情之工单费用列表
export function getNetworkDetailOrderFeeList(data, id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailOrderFeeList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
//获取服务商详情之服务商结算
export function getNetworkDetailModuleSettlementList(data, id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailModuleSettlementList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
//获取服务商详情之资质认证信息
export function getNetworkDetailAuthenField(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailAuthenField/' + id,
    method: 'get',
    headers: token,
  })
}
//获取认证字段列表
export function getNetworkfieldcList(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/getList/' + type,
    method: 'post',
    headers: token,
    data,
  })
}
//批量删除认证字段
export function getNetworkDelete(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/delete/' + type,
    method: 'delete',
    headers: token,
    data,
  })
}
//批量启用或禁用认证字段
export function getNetworkDisable(data, status, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/disable/' + type,
    method: 'delete',
    headers: token,
    data,
    params: { status },
  })
}
//根据认证字段ID获取认证字段详情
export function getNetworkDetail(id, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/authen/field/getDetail/${type}/${id}`,
    method: 'get',
    headers: token,
  })
}
//保存或更新认证字段
export function getNetworkfieldcSave(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/save/' + type,
    method: 'post',
    headers: token,
    data,
  })
}

//获取人员等级列表
export function getNetworkLevelList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/getList',
    method: 'post',
    headers: token,
    data,
  })
}
//根据人员等级ID批量删除
export function getNetworkLevelDelete(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/delete',
    method: 'delete',
    headers: token,
    data,
  })
}
//批量启用或禁用人员等级
export function getNetworkLevelDisable(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/disable',
    method: 'delete',
    headers: token,
    data,
    params: { status },
  })
}
//新增或更新人员等级
export function getNetworkLevelDetail(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/emp/level/getDetail/${id}`,
    method: 'get',
    headers: token,
  })
}
//新增或更新人员等级
export function getNetworkfieldcLevelSave(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/save',
    method: 'post',
    headers: token,
    data,
  })
}

//获取人员技能列表
export function getNetworkSkillList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/getList',
    method: 'post',
    headers: token,
    data,
  })
}
//删除技能
export function getNetworkSkillDelete(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/delete',
    method: 'delete',
    headers: token,
    data,
  })
}
//批量启用或禁用技能
export function getNetworkSkillDisable(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/disable',
    method: 'delete',
    headers: token,
    data,
    params: { status },
  })
}
//根据技能ID获取技能详情
export function getNetworkSkillDetail(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/emp/skill/getDetail/${id}`,
    method: 'get',
    headers: token,
  })
}
//新增或更新服务商人员技能
export function getNetworkfieldcSkillSave(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/save',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取服务商人员字段下拉数据
export function networkEmpFieldSelect() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/networkEmpFieldSelect',
    method: 'get',
    headers: token,
  })
}
// 获取服务商人员等级下拉数据
export function getNetworkEmpLevelSelect(data: { name: string; limit: number; page: number }) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkEmpLevelSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取服务商人员技能下拉数据
export function getNetworkEmpSkillSelect(data: { name: string; limit: number; page: number }) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkEmpSkillSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取所有服务商导出字段
export function getNetworkExportFields() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/getNetworkExportFields',
    method: 'get',
    headers: token,
  })
}
// 获取服务商初始化系统导出字段
export function getNetworkSysInitExportField() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/getNetworkSysInitExportField',
    method: 'get',
    headers: token,
  })
}
// 获取服务商自定义字段
export function getNetworkCustomField() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/getNetworkCustomField',
    method: 'get',
    headers: token,
  })
}
// 保存并导出服务商字段
export function saveAndExportNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/saveAndExportNetworkField',
    method: 'post',
    headers: token,
    data,
    responseType: 'blob',
  })
}
// 保存服务商导出字段
export function saveExportNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 根据服务商分类或区域查询对应的服务商
interface NetworkOptional {
  area: string
  city: string
  limit: number
  name: string
  page: number
  province: string
  type: number
  typeId: string | number
}
export function getNetworkSelect(data: NetworkOptional) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkSelect',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新服务商接单策略
 * @param {boolean} autoSureReceiveOrder 是否自动接单：false-手动确认，true-自动接单
 * @param {Array<string>} data 服务商ID
 */
export function updateAutoSureReceiveOrder(autoSureReceiveOrder: boolean, data: Array<string>) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAutoSureReceiveOrder?autoSureReceiveOrder=${autoSureReceiveOrder}`,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新服务商审核取消工单策略
 * @param {boolean} autoCheckCancelOrder 是否自动审核取消工单：false-手动审核，true-自动审核
 * @param {Array<string>} data 服务商ID
 */
export const updateAutoCheckCancelOrder = (autoCheckCancelOrder: boolean, data: Array<string>) => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAutoCheckCancelOrder?autoCheckCancelOrder=${autoCheckCancelOrder}`,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新服务商审核结单策略
 * @param {boolean} autoCheckEndOrder 是否自动审核结单：false-手动审核，true-自动审核
 * @param {Array<string>} data 服务商ID
 */
export const updateAutoCheckEndOrder = (autoCheckEndOrder: boolean, data: Array<string>) => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAutoCheckEndOrder?autoCheckEndOrder=${autoCheckEndOrder}`,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新允许更改备件价格
 * @param {boolean} enableUpdateSparePrice 是否允许更改备件价格：false-关闭，true-允许修改
 * @param {Array<string>} data 服务商ID
 */
export const enableUpdateSparePrice = (enableUpdateSparePrice: boolean, data: Array<string>) => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/enableUpdateSparePrice?enableUpdateSparePrice=${enableUpdateSparePrice}`,
    method: 'post',
    headers: token,
    data,
  })
}
/**
 * 批量更改提现手续费
 */
export const updateOrderWithdrawHandlingFee = (data) => {
  return request({
    url: `/network/strategy/updateOrderWithdrawHandlingFee`,
    method: 'post',
    data,
  })
}
/**
 * 批量更改服务商团队模式
 */
export const updateNetworkTeamType = (data, teamType) => {
  return request({
    url: `/network/updateNetworkTeamType?teamType=${teamType}`,
    method: 'post',
    data,
  })
}
/**
 * 批量更改提现策略
 */
export const updateWithdrawEmpRoot = (data) => {
  return request({
    url: `/network/strategy/updateWithdrawEmpRoot`,
    method: 'post',
    data,
  })
}
/**
 * 批量更改查询费用策略
 */
export const updateSelectFeeEmpRoot = (data) => {
  return request({
    url: `/network/strategy/updateSelectFeeEmpRoot`,
    method: 'post',
    data,
  })
}
